package edu.nf.project.webs.storeOperation;

import edu.nf.project.services.exception.derivedAnomalies.DishException;
import edu.nf.project.services.response.BaseController;
import edu.nf.project.services.response.ResultVO;
import edu.nf.project.services.storeOperation.CustomerOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/customerItem")
public class CustomerOrderItemController extends BaseController {
    @Autowired
    private CustomerOrderItemService customerOrderItemService;

    @GetMapping("/{dishId}")
    public ResultVO<Boolean> getDishInfo(@RequestParam Integer orderId, @RequestParam Integer dishId, @RequestParam Integer quantity) {
        try {
            Boolean flag = customerOrderItemService.addItem(orderId, dishId, quantity);
            return success(flag);
        } catch (Exception e) {
            if (e instanceof DishException) {
                throw e;
            }
            throw new DishException(40000, "系统错误，请稍后重试");
        }
    }
}
